<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/admin/common/inc/incSession.jsp" %>
<jsp:include page="/admin/common/inc/Top.jsp" />
<%
	
	String srchEventType = util.getStr(request.getParameter("srchEventType"));
	String srchCategoryCode = util.getStr(request.getParameter("srchCategoryCode"));
	String srchCond 	= util.getStr(request.getParameter("srchCond")); 
	String srchContent 	= util.getStr(request.getParameter("srchContent"));
	String srchStdt 	= util.getStr(request.getParameter("srchStdt"));
	String srchEndt 	= util.getStr(request.getParameter("srchEndt"));
	String srchUseYn 	= util.getStr(request.getParameter("srchUseYn"));


	// paging
	String perRow 		= util.getStr(request.getParameter("perRow"));
	String startRow 	= util.getStr(request.getParameter("startRow"));
	String currentPage 	= util.getStr(request.getParameter("currentPage"));
	
	perRow = "".equals(perRow) ?"10":perRow;
	startRow = "".equals(startRow)?"0":startRow;
	currentPage = "".equals(currentPage)?"1":currentPage;
	
	
%>
<script type="text/javascript">
	
	$(document).ready(function() {

		createCalendar();
		
	    // 달력 토글
		$('#calToggle').bind('click', function(event){
			
				$('#dhtmlxDblCalendar').toggle();
		});
		
	    //	초기값 셋팅
		$("#srchEventType").val("<%=srchEventType%>");
		$("#srchCategoryCode").val("<%=srchCategoryCode%>");
		$("#srchCond").val("<%=srchCond%>");
		$("#srchContent").val("<%=srchContent%>");
		$("#srchStdt").val("<%=srchStdt%>");
		$("#srchEndt").val("<%=srchEndt%>");
		$("#srchUseYn").val("<%=srchUseYn%>");
		$("#startRow").val("<%=startRow%>");
		$("#currentPage").val("<%=currentPage%>");
		
		
		
		//	검색
		$("#btnSearch").click(function() {
			
			$("#listForm").attr("action","/admin/event/eventList.jsp");
			$("#listForm").attr("target","_top");		
			$("#listForm").submit();
			
		});
		
		//	페이지 이동
		jQuery("a[name^='goPage']").click(function(){
			
			$("#startRow").val($(this).attr("startRow"));
			$("#currentPage").val($(this).attr("currentPage"));
			$("#listForm").attr("action","/admin/event/eventList.jsp");
			$("#listForm").attr("target","_top");		
			$("#listForm").submit();
			
		});
		
		
		//	등록
		$("#btnCreate").click(function() {
			
			$("#listForm").attr("action","/admin/event/eventInsert.jsp");
			$("#listForm").attr("target","_top");		
			$("#listForm").submit();
			
		});
		
		//	초기화
		$("#btnReset").click(function() {
			
			$("input[type=text]").val("");
			$("select").val("");
		});
		
		// 상세
	    jQuery("a[name^='detailAnc']").click(function(){
	    	
	    	$('#eventId').val($(this).attr("eventId"));
	    	$("#listForm").attr("action","/admin/event/eventDetail.jsp");
			$("#listForm").attr("target","_top");		
			$("#listForm").submit();

	    });
		
	});
		
</script>	
	<body>
		<!-- header -->
		<div id="header">
			<jsp:include page="/admin/common/inc/Header.jsp" />
		</div>
		<!-- //header -->
		
		<!-- wrap -->
		<div id="wrap">
		
			<!-- contentWrap -->
			<div id="contentWrap">
			
				<!-- topmenu -->
				<jsp:include page="/admin/common/inc/TopMenu.jsp" />
				<!-- //topmenu -->
				
				
				<div id="conts">
				
					<div class="main_view clfix">
						<!-- content -->
						
						
						<form id="listForm" name="listForm" method="post">
						<input type="hidden" name="eventId" id="eventId" value="" />
						<input type="hidden" name="startRow" id="startRow" value="" />
						<input type="hidden" name="currentPage" id="currentPage" value="" />
						
						<div class="section_main" style="height: 700px;">
							
							
							<!--board input-->
							<table class="bdc_input mb10">
								<colgroup><col width="20%"><col width="32%"><col width="20%"><col width="28%"></colgroup>
								<tr>
									<th class="cth">이벤트 타입</th>
									<td class="ctd">
										<select id="srchEventType" name="srchEventType">
											<option value="">전체</option>
										<%
											param.clear();
											param.put("p_code","ET");
											ArrayList rs =	(ArrayList)sqlMap.queryForList("Common.selectCodeList",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
											
											for( int i = 0 ; i < rs.size() ; i++){
										%>
											<option value="<%=util.getStr(((HashMap)rs.get(i)).get("CODE")) %>"><%=util.getStr(((HashMap)rs.get(i)).get("NAME")) %></option>
										<%		
											}
										%>
										</select>
									</td>
									<th class="cth">카테고리</th>
									<td class="ctd">
										<select id="srchCategoryCode" name="srchCategoryCode">
											<option value="">전체</option>
										<%
											param.clear();
											param.put("p_code","CT");
											rs =	(ArrayList)sqlMap.queryForList("Common.selectCodeList",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
											
											for( int i = 0 ; i < rs.size() ; i++){
										%>
											<option value="<%=util.getStr(((HashMap)rs.get(i)).get("CODE")) %>"><%=util.getStr(((HashMap)rs.get(i)).get("NAME")) %></option>
										<%		
											}
										%>
										</select>
									</td>
								</tr>
								<tr>
									<th class="cth">검색조건</th>
									<td class="ctd">
										<select id="srchCond" name="srchCond">
											<option value="">선택</option>
											<option value="EVENT_NAME">이벤트명</option>
											<option value="PRODUCT_NAME">상품명</option>
											<option value="DESCRIPTION">설명</option>
										</select>
										<input type="text" class="txt" style="width:150px;" id="srchContent" name="srchContent" value="">
									</td>
									<th class="cth">사용여부</th>
									<td class="ctd">
										<select id="srchUseYn" name="srchUseYn">
											<option value="">전체</option>
											<option value="Y">Y</option>
											<option value="N">N</option>
										</select>
									</td>
								</tr>
								<tr>
									<th class="cth">등록일자</th>
									<td class="ctd" colspan="3">
										<input id="srchStdt" name="srchStdt" type="text" class="txt" style="width: 60px;" readonly="true" value=""/> ~ 
							   	   		<input id="srchEndt" name="srchEndt" type="text" class="txt" style="width: 60px;" readonly="true" value=""/>
							   			<img name="calToggle" id="calToggle" src ="/common/calendar/imgs/icon_minicalendar.gif" style="cursor: pointer;"/>
									    <div id="dhtmlxDblCalendar" style="position: absolute;"></div>
									</td>
								</tr>
							</table>
							<!--//board input-->
							
							
							<!--btn-->
							<div class=" al_center ">
								<button type="button" id="btnSearch">조회</button>
								<button type="button" id="btnReset">초기화</button>
							</div>
							<!--//btn-->
							<!--btn-->
							<div class="al_right mb10">
								<button type="button" id="btnCreate">등록</button>
							</div>
							<!--//btn-->
						
						
							<!--board list-->
							<div class="board_list mb10">
								<table style="table-layout:fixed">
									<thead>
										<tr>
											<th width="20">Event ID</th>
											<th width="50">썸네일</th>
											<th width="100">이벤트타입</th>
											<th width="100">카테고리</th>
											<th width="100">이벤트명</th>
											<th width="200">이벤트 기간</th>
											<th width="200">활동 기간</th>
											<th width="100">당첨 발표일</th>
											<th width="100">경품 지급일</th>
											<th width="100">이벤트 등록일</th>
											<th width="70">스마트폰<br/>이벤트</th>
											<th width="70">사용여부</th>
										</tr>
									</thead>
									<tbody id="prodList" name="prodList">
									<%
									
									
										param.clear();
									
										param.put("eventType",srchEventType);
										param.put("categoryCode",srchCategoryCode);
										param.put("srchCond",srchCond);
										param.put("srchContent",srchContent);
										param.put("srchStdt",srchStdt);
										param.put("srchEndt",srchEndt);
										param.put("srchUseYn",srchUseYn);
										
										// paging
										param.put("perRow", perRow);
										param.put("startRow", startRow);
										rs =	(ArrayList)sqlMap.queryForList("AdminEvent.selectEventList",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
										
										HashMap map	 = 	(HashMap)sqlMap.queryForObject("AdminEvent.selectEventListTotal",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
										
										for( int i = 0 ; i < rs.size() ; i++){
									%>
							            <tr>
							                <td><%=util.getStr(((HashMap)rs.get(i)).get("EVENT_ID")) %></td>
							                <td><img src="/<%=util.getStr(((HashMap)rs.get(i)).get("THUMB_IMG")) %>" onerror="this.src='/common/images/no_prof_img.jpg'" style="width: 30px; height: 30px;" /></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("EVENT_TYPE")) %></td>
							                <td><%=util.getStr(((HashMap)rs.get(i)).get("CATEGORY_CODE")) %></td>
											<td title="<%=util.getStr(((HashMap)rs.get(i)).get("EVENT_NAME")) %>" style="text-overflow:ellipsis; overflow:hidden; white-space:nowrap;"><a href="javascript:void(0)" name="detailAnc" eventId="<%=((HashMap)rs.get(i)).get("EVENT_ID") %>"><%=util.getStr(((HashMap)rs.get(i)).get("EVENT_NAME")) %></a></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("REQ_FDATE")) %> ~ <%=util.getStr(((HashMap)rs.get(i)).get("REQ_TDATE")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("REVIEW_FDATE")) %> ~ <%=util.getStr(((HashMap)rs.get(i)).get("REVIEW_TDATE")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("WIN_DATE")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("PROVIDE_DATE")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("REG_DATE")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("SMART_YN")) %></td>
											<td><%=util.getStr(((HashMap)rs.get(i)).get("USE_YN")) %></td>
							            </tr>
									<%		
										}
									%>
									<%
										if( 0 >= rs.size()){
									%>							            
						            	<tr class="nodata">
						                     <td align="center" colspan="8">조회된 Data 가 없습니다.</td>
						                </tr>
									<%
										}
									%>							            
									</tbody>
								</table>
							</div>
							<!--//board list-->
							
						
						</div>
						
						<!--//board list-->						
						<div class="section_main" style="height: 45px;">
							<%@ include file="/common/inc/paging.jsp" %>
						</div>
						</form>
						
						<!-- //content -->
						
					</div>
					
				</div>
				
			</div>
			<!-- //contentWrap -->
			
		</div>
		
		<div id="footer" style="background: url('/layoutSample/footer.png') no-repeat; height: 150px;">
		</div>
		
		<!-- //wrap -->
		
		
	
	</body>
</html>